package com.mysql.shujuku.sql;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.example.mysql.shujuku.MyHelper;

public class MyDatabase {
    Context mContext;
    MyHelper myHelper;
    SQLiteDatabase sqLiteDatabase;
    Cursor cursor;
    public MyDatabase(Context context){
        mContext = context;
        myHelper = new MyHelper(mContext);
        sqLiteDatabase = myHelper.getReadableDatabase();
    }
    public void insert(){
        ContentValues values = new ContentValues();
        values.put("name","橙子");
        values.put("price","8");
        sqLiteDatabase.insert("infor",null,values);
        sqLiteDatabase.close();
        myHelper.close();

    }
    public void update(){
        ContentValues values = new ContentValues();
        values.put("price","10");
        sqLiteDatabase.update("infor",values,"name=?",new String[]{"橙子"});
        sqLiteDatabase.close();
        myHelper.close();
    }
    public void delete(){
        sqLiteDatabase.delete("infor","name=?",new String[]{"橙子"});
        sqLiteDatabase.close();
        myHelper.close();
    }
    public boolean select(){
        sqLiteDatabase.query("infor",null,"name=?",new String[]{"橙子"},null,null,null);
        boolean result = cursor.moveToNext();
        cursor.close();
        sqLiteDatabase.close();
        myHelper.close();
        return result;

    }
}
